using UnityEngine;
using QFramework;
using QAssetBundle;

namespace ProjectSurviver
{
	public partial class Boom : GamePlayObject
	{
        public override Collider2D Collider2D => SelfCollider2D;

		public static void Execute()
		{
			foreach (var enemyObj in GameObject.FindGameObjectsWithTag("Enemy"))
			{
				var enemy = enemyObj.GetComponent<Enemy>();
				if(enemy && enemy.gameObject.activeSelf)
				{
					DamageSystem.CalculateDamage(Global.BoomDamage.Value, enemy); // 计算伤害
					enemy.Hurt(Global.BoomDamage.Value); // 受伤
				}
			}
			AudioKit.PlaySound(Sfx.BOOM);
			UIGamePanel.FlashScreen.Trigger(); // 触发屏幕闪烁效果
			CameraController.Shake(); // 相机震动
		}

        void OnTriggerEnter2D(Collider2D other)
        {
            if(other.GetComponent<CollectableArea>())
			{
				Execute(); // 执行爆炸效果

				this.DestroyGameObjGracefully();
			}
        }
    }
}
